#[cfg(test)]
mod test_chapter4 {


    use std::cell::RefCell;
    use std::rc::Rc;
    // p112  使用 RefCell<T> 保证内部可变.  实现链表,该实现会造成内存泄漏
    #[test]
    fn test_refcell() {
        type NodePtr<T> = Option<Rc<RefCell<Node<T>>>>;

        struct  Node<T> {
            data: T,
            next: NodePtr<T>,
        }

        impl<T> Drop for Node<T> {
            fn drop(&mut self) {
                println!("Dropping!");
            }
        }

        let first = Rc::new(RefCell::new(Node{
            data: 1,
            next: None,
        }));

        let second = Rc::new(RefCell::new(Node{
            data: 2,
            next: Some(first.clone()),
        }));

        first.borrow_mut().next = Some(second.clone());
        second.borrow_mut().next = Some(first.clone());
    }
}